package com.it.flowable.service.leave.bpm;

import com.it.flowable.common.constants.BpmCommonConstant;
import com.it.flowable.common.vo.leave.LeaveBpmCreatTaskParamVO;
import com.it.flowable.common.vo.leave.LeaveBpmParamVO;
import com.it.flowable.entity.leave.ActFlwMainLeaveVO;
import com.it.flowable.entity.leave.ActFlwTaskLeaveVO;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 请假工作流 封装数据
 */
@Service
public class BpmLeavePackParamUtil {

    /**
     * 首次提交申请流程数据封装
     *
     * @param mainLeaveVO
     * @param taskLeaveVO
     * @return
     */
    public Map<String, Object> packageStartApplyProcess(ActFlwMainLeaveVO mainLeaveVO, ActFlwTaskLeaveVO taskLeaveVO) {
        Map<String, Object> paramMap = new HashMap<>();
        LeaveBpmParamVO leaveBpmParamVO = new LeaveBpmParamVO();
        leaveBpmParamVO.setCMainId(mainLeaveVO.getCMainId());
        leaveBpmParamVO.setCAppCde(taskLeaveVO.getCAppCde());
        leaveBpmParamVO.setCAppRmk(taskLeaveVO.getCAppRmk());
        // 请假申请流程数据
        LeaveBpmCreatTaskParamVO creatTaskParamVO = new LeaveBpmCreatTaskParamVO();
        creatTaskParamVO.setCTaskKind(BpmCommonConstant.IS_NO);
        creatTaskParamVO.setCTaskNo(taskLeaveVO.getCTaskNo());
        creatTaskParamVO.setCTaskType(taskLeaveVO.getCTaskType());
        creatTaskParamVO.setCAppCde(taskLeaveVO.getCAppCde());
        creatTaskParamVO.setCAppRmk(taskLeaveVO.getCAppRmk());
        creatTaskParamVO.setCDays(taskLeaveVO.getCDays());
        creatTaskParamVO.setCOwnerId(taskLeaveVO.getCAppCde());
        creatTaskParamVO.setCUserId(taskLeaveVO.getCAppCde()); // 这个必须要有
        leaveBpmParamVO.setCBpmCreatTaskParamVO(creatTaskParamVO);

        paramMap.put("LeaveBpmParamVO", leaveBpmParamVO);
        return paramMap;
    }

    public Map<String, Object> packageStartChkProcess(Map<String, Object> reqMap, ActFlwTaskLeaveVO taskLeaveVO) {
        Map<String, Object> paramMap = new HashMap<>();
        LeaveBpmParamVO leaveBpmParamVO = new LeaveBpmParamVO();
        leaveBpmParamVO.setCTaskId(MapUtils.getString(reqMap, "cTaskId"));
        leaveBpmParamVO.setCMainId(MapUtils.getString(reqMap, "cMainId"));
        leaveBpmParamVO.setCTaskType(MapUtils.getString(reqMap, "cTaskType"));
        leaveBpmParamVO.setCToTaskType(MapUtils.getString(reqMap, "cToTaskType"));
        LeaveBpmCreatTaskParamVO creatTaskParamVO = new LeaveBpmCreatTaskParamVO();
        BeanUtils.copyProperties(taskLeaveVO, creatTaskParamVO);
        creatTaskParamVO.setCOwnerId(MapUtils.getString(reqMap, "cOwnerId"));
        creatTaskParamVO.setCUserId(MapUtils.getString(reqMap, "cUserId"));
        leaveBpmParamVO.setCBpmCreatTaskParamVO(creatTaskParamVO);

        paramMap.put("LeaveBpmParamVO", leaveBpmParamVO);
        return paramMap;
    }

    public Map<String, Object> packageCancelApplyProcess(Map<String, Object> reqMap) {
        Map<String, Object> paramMap = new HashMap<>();
        LeaveBpmParamVO leaveBpmParamVO = new LeaveBpmParamVO();
        leaveBpmParamVO.setCTaskId(MapUtils.getString(reqMap, "cTaskId"));
        leaveBpmParamVO.setCMainId(MapUtils.getString(reqMap, "cMainId"));
        leaveBpmParamVO.setCTaskType(MapUtils.getString(reqMap, "cTaskType"));
        leaveBpmParamVO.setCToTaskType(MapUtils.getString(reqMap, "cToTaskType"));

        paramMap.put("LeaveBpmParamVO", leaveBpmParamVO);
        return paramMap;
    }

    public Map<String, Object> packageFirstChkProcessOK3(Map<String, Object> reqMap, ActFlwTaskLeaveVO actFlwTaskLeaveVO) {
        Map<String, Object> paramMap = new HashMap<>();
        LeaveBpmParamVO leaveBpmParamVO = new LeaveBpmParamVO();
        leaveBpmParamVO.setCTaskId(MapUtils.getString(reqMap, "cTaskId"));
        leaveBpmParamVO.setCMainId(MapUtils.getString(reqMap, "cMainId"));
        leaveBpmParamVO.setCTaskType(MapUtils.getString(reqMap, "cTaskType"));
        leaveBpmParamVO.setCToTaskType(MapUtils.getString(reqMap, "cToTaskType"));
        leaveBpmParamVO.setCOperCde(MapUtils.getString(reqMap, "cOperCde"));

        paramMap.put("LeaveBpmParamVO", leaveBpmParamVO);
        return paramMap;
    }

    public Map<String, Object> packageFirstChkProcessOK3To5(Map<String, Object> reqMap, ActFlwTaskLeaveVO taskLeaveVO) {
        Map<String, Object> paramMap = new HashMap<>();
        LeaveBpmParamVO leaveBpmParamVO = new LeaveBpmParamVO();
        leaveBpmParamVO.setCTaskId(MapUtils.getString(reqMap, "cTaskId"));
        leaveBpmParamVO.setCMainId(MapUtils.getString(reqMap, "cMainId"));
        leaveBpmParamVO.setCTaskType(MapUtils.getString(reqMap, "cTaskType"));
        leaveBpmParamVO.setCToTaskType(MapUtils.getString(reqMap, "cToTaskType"));
        LeaveBpmCreatTaskParamVO creatTaskParamVO = new LeaveBpmCreatTaskParamVO();
        BeanUtils.copyProperties(taskLeaveVO, creatTaskParamVO);
        creatTaskParamVO.setCOwnerId(MapUtils.getString(reqMap, "cOwnerId"));
        creatTaskParamVO.setCUserId(MapUtils.getString(reqMap, "cUserId"));
        leaveBpmParamVO.setCBpmCreatTaskParamVO(creatTaskParamVO);

        paramMap.put("LeaveBpmParamVO", leaveBpmParamVO);
        return paramMap;
    }

    public Map<String, Object> packageFirstChkProcessBack3(Map<String, Object> reqMap, ActFlwTaskLeaveVO taskLeaveVO) {
        Map<String, Object> paramMap = new HashMap<>();
        LeaveBpmParamVO leaveBpmParamVO = new LeaveBpmParamVO();
        leaveBpmParamVO.setCTaskId(MapUtils.getString(reqMap, "cTaskId"));
        leaveBpmParamVO.setCMainId(MapUtils.getString(reqMap, "cMainId"));
        leaveBpmParamVO.setCTaskType(MapUtils.getString(reqMap, "cTaskType"));
        leaveBpmParamVO.setCToTaskType(MapUtils.getString(reqMap, "cToTaskType"));
        leaveBpmParamVO.setCTaskKind(MapUtils.getString(reqMap, "cTaskKind"));
        LeaveBpmCreatTaskParamVO creatTaskParamVO = new LeaveBpmCreatTaskParamVO();
        BeanUtils.copyProperties(taskLeaveVO, creatTaskParamVO);
        creatTaskParamVO.setCOwnerId(MapUtils.getString(reqMap, "cOwnerId"));
        creatTaskParamVO.setCUserId(MapUtils.getString(reqMap, "cUserId"));
        leaveBpmParamVO.setCBpmCreatTaskParamVO(creatTaskParamVO);

        paramMap.put("LeaveBpmParamVO", leaveBpmParamVO);
        return paramMap;
    }

    public Map<String, Object> packageFirstChkProcessOK5(Map<String, Object> reqMap, ActFlwTaskLeaveVO actFlwTaskLeaveVO) {
        Map<String, Object> paramMap = new HashMap<>();
        LeaveBpmParamVO leaveBpmParamVO = new LeaveBpmParamVO();
        leaveBpmParamVO.setCTaskId(MapUtils.getString(reqMap, "cTaskId"));
        leaveBpmParamVO.setCMainId(MapUtils.getString(reqMap, "cMainId"));
        leaveBpmParamVO.setCTaskType(MapUtils.getString(reqMap, "cTaskType"));
        leaveBpmParamVO.setCToTaskType(MapUtils.getString(reqMap, "cToTaskType"));
        leaveBpmParamVO.setCOperCde(MapUtils.getString(reqMap, "cOperCde"));

        paramMap.put("LeaveBpmParamVO", leaveBpmParamVO);
        return paramMap;
    }

    public Map<String, Object> packageFirstChkProcessBack5(Map<String, Object> reqMap, ActFlwTaskLeaveVO taskLeaveVO) {
        Map<String, Object> paramMap = new HashMap<>();
        LeaveBpmParamVO leaveBpmParamVO = new LeaveBpmParamVO();
        leaveBpmParamVO.setCTaskId(MapUtils.getString(reqMap, "cTaskId"));
        leaveBpmParamVO.setCMainId(MapUtils.getString(reqMap, "cMainId"));
        leaveBpmParamVO.setCTaskType(MapUtils.getString(reqMap, "cTaskType"));
        leaveBpmParamVO.setCToTaskType(MapUtils.getString(reqMap, "cToTaskType"));
        LeaveBpmCreatTaskParamVO creatTaskParamVO = new LeaveBpmCreatTaskParamVO();
        BeanUtils.copyProperties(taskLeaveVO, creatTaskParamVO);
        creatTaskParamVO.setCOwnerId(MapUtils.getString(reqMap, "cOwnerId"));
        creatTaskParamVO.setCUserId(MapUtils.getString(reqMap, "cUserId"));
        leaveBpmParamVO.setCBpmCreatTaskParamVO(creatTaskParamVO);

        paramMap.put("LeaveBpmParamVO", leaveBpmParamVO);
        return paramMap;
    }

}
